<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../VueJs/vue.js"></script>
</head>

<body>
    <div id="root">
        <h2 @click="add">n的值为{{n}}</h2>
        <button @click="bye">销毁vm</button>
    </div>
</body>
<script>
    Vue.config.productionTip = false;
    Vue.config.devtools = true;
    const vm = new Vue({
        el: '#root',
        data: {
            n: 1
        },
        methods: {
            add: function () {
                console.log('add');
                this.n++;
            },
            bye: function () {
                this.$destroy();
            }
        },
        watch: {
            n: {
                handler: function () {
                    console.log('n变了');
                }
            }
        },
        beforeCreate() {
            console.log('beforeCreate');
        },
        created() {
            console.log('created');
        },
        beforeMount() {
            console.log('beforeMount');
        },
        mounted() {
            console.log("mounted");
        },
        beforeUpdate() {
            console.log('beforeUpdate');
        },
        updated() {
            console.log("updated");
        },
        beforeDestroy() {
            console.log('beforeDestroy');
            console.log(this.n);
            this.add();
            console.log(this.n);
        },
        destroyed() {
            console.log('destroyed');
        },

    });

</script>

</html>